# 不使用封装的问题示例
class UnsafeCar:
    def __init__(self):
        self.speed = 0
        self.max_speed = 200
        self.fuel = 50


# 使用封装的安全示例
class SafeCar:
    def __init__(self):
        self._speed = 0  # 受保护的属性
        self._max_speed = 200
        self._fuel = 50

    def accelerate(self, increase):
        if self._fuel > 0:
            if self._speed + increase <= self._max_speed:
                self._speed += increase
                self._fuel -= increase * 0.1  # 加速消耗燃油
                print(f"加速到 {self._speed} km/h")
            else:
                self._speed = self._max_speed
                print(f"已达最大速度 {self._max_speed} km/h")
        else:
            print("燃油已耗尽，无法加速")

    def brake(self, decrease):
        if self._speed - decrease >= 0:
            self._speed -= decrease
            print(f"减速到 {self._speed} km/h")
        else:
            self._speed = 0
            print("车辆已停止")

    def get_speed(self):
        return self._speed

    def get_fuel_level(self):
        return self._fuel
